package com.globallogic.training.javase.university.schedule;

/**
 * This class represents all the auditoriums available
 * in the university for lectures, seminars and examinations.
 * @author Ivan Moisiienko
 * @version 0.2 2013/05/23
 */
public class Auditorium implements Comparable<Auditorium>{
	
	private int auditoriumNumber;
	
	/**
	 * @param room should be positive
	 */
	public Auditorium(int room) {
		

		if (room < 1) {
			throw new IllegalArgumentException(
					"Auditorium number should be positive");
		}
		
		this.auditoriumNumber = room;
	}
	
	public Auditorium(String room) {
		int audNumber = Integer.parseInt(room);
		
		if (audNumber < 1) {
			throw new IllegalArgumentException(
					"Auditorium number should be positive");
		}
		
		this.auditoriumNumber = audNumber;
	}
	
	public int getAuditoriumNumber() {
		return auditoriumNumber;
	};
	
	public String toString() {
		return "aud. " + auditoriumNumber;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + auditoriumNumber;
		return result;
	}
	
	@Override
	public boolean equals(Object otherObject) {
		if (this == otherObject) {
			return true;
		}
		if (otherObject == null) {
			return false;
		}
		if (getClass() != otherObject.getClass()) {
			return false;
		}
		
		Auditorium other = (Auditorium) otherObject;
		if (this.auditoriumNumber == other.auditoriumNumber) {
			return true;
		}
		return false;
	}
	
	@Override
	public int compareTo(Auditorium other) {
		int compare = this.auditoriumNumber - other.auditoriumNumber;
		
		if (compare > 0) {
			return 1;
		}		
		if (compare < 0) {
			return -1;
		}
		return 0;
	}
	
}
